package com.sls.game.dao.yun.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.sls.game.dao.impl.SuperDAO;
import com.sls.game.dao.yun.YunDAO;
import com.sls.game.page.Pagination;
import com.sls.game.pojo.yunen.YunEnProduct;

@Repository("yunDAO")
public class YunDAOImpl extends SuperDAO<YunEnProduct> implements YunDAO {

	@Override
	public void insert(YunEnProduct product) {
		this.getSqlSession().insert("mybatis.xml.YunEnProductMapper.insert",
				product);
	}

	@Override
	public void update(YunEnProduct product) {
		this.getSqlSession().insert("mybatis.xml.YunEnProductMapper.update",
				product);
	}

	@Override
	public YunEnProduct queryById(String id) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.YunEnProductMapper.selectByPrimaryKey", id);
	}

	@Override
	public YunEnProduct queryByProductId(String productId) {
		return this.getSqlSession().selectOne(
				"mybatis.xml.YunEnProductMapper.queryByProductId", productId);
	}

	@Override
	public Pagination<YunEnProduct> queryPage(YunEnProduct product) {
		Pagination<YunEnProduct> paginationList = null;
		Integer rowCount = queryRowCount(product);

		product.calculate();
		List<YunEnProduct> list = queryGoodsInfoList(product);
		paginationList = this.queryPagination(rowCount, list, product);
		return paginationList;
	}

	/**
	 * 查询记录总数
	 * 
	 * @param product
	 * @return
	 */
	private Integer queryRowCount(YunEnProduct product) {
		Integer rowCount = this.getSqlSession().selectOne(
				"mybatis.xml.YunEnProductMapper.queryRowCount", product);
		return rowCount;
	}

	/**
	 * 记录结果集list
	 * 
	 * @param product
	 * @return
	 */
	private List<YunEnProduct> queryGoodsInfoList(YunEnProduct product) {
		List<YunEnProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.YunEnProductMapper.queryYunProductInfoList",
				product);
		return list;
	}

	@Override
	public List<YunEnProduct> queryAllProduct(YunEnProduct product) {
		List<YunEnProduct> list = this.getSqlSession().selectList(
				"mybatis.xml.YunEnProductMapper.queryAllYunInfo", product);
		return list;
	}

}
